#include <stdio.h>
#include <stdlib.h>
#define MAX_SIZE 100

typedef struct Queue
{
    int *base;
    int rear;
    int front;
}Queue;
void InitQueue(Queue *Q);
void InitQueue(Queue *Q)
{
    Q->base=(int *)malloc(MAX_SIZE*sizeof(int));
    if(Q->base==NULL)
    {
        printf("OVERFLOW");
        return;
    }
    Q->front=Q->rear=0;
}
void EnQueue(Queue *Q,int elem);
void EnQueue(Queue *Q,int elem)
{
    if(Q->front==(Q->rear+1)%MAX_SIZE)
    {
        printf("OVERFLOW");
        return;
    }
    Q->base[Q->rear]=elem;
    Q->rear=(Q->rear+1)%MAX_SIZE;
}
void DeQueue(Queue *Q,int *elem);
void DeQueue(Queue *Q,int *elem)
{
    if(Q->front==Q->rear)
    {
        printf("EMPTY");
        return;
    }
    *elem=Q->base[Q->front];
    Q->front=(Q->front+1)%MAX_SIZE;
}
int QueueLength(Queue *Q);
int QueueLength(Queue *Q)
{
    return (Q->rear-Q->front+MAX_SIZE)%MAX_SIZE;
}
int main()
{
    Queue Q;
    int elem;
    InitQueue(&Q);
    EnQueue(&Q,1);
    EnQueue(&Q,2);
    EnQueue(&Q,3);
    EnQueue(&Q,4);
    EnQueue(&Q,5);
    printf("%d\n",QueueLength(&Q));
    DeQueue(&Q,&elem);
    printf("%d\n",elem);
    printf("%d\n",QueueLength(&Q));

}